package models;

import java.util.List;

import javax.persistence.Transient;

import models.mappers.SystemMenuMapper;
import org.apache.ibatis.session.SqlSession;

import com.aton.db.SessionFactory;

public class SystemMenu implements java.io.Serializable {
		public final static String TABLE_NAME="system_menu";
		public String menuid;
		public String menuname;
		public String menuurl;
		public String parentid;
		public boolean isend;
		@Transient
		public List<SystemMenu> children;
		public SystemMenu(){
			
		}
		public SystemMenu(String menuid, String menuname, String menuurl,
				String parentid) {
			super();
			this.menuid = menuid;
			this.menuname = menuname;
			this.menuurl = menuurl;
			this.parentid = parentid;
		}
		
		public String getMenuid() {
			return menuid;
		}
		public void setMenuid(String menuid) {
			this.menuid = menuid;
		}
		public String getMenuname() {
			return menuname;
		}
		public void setMenuname(String menuname) {
			this.menuname = menuname;
		}
		public String getMenuurl() {
			return menuurl;
		}
		public void setMenuurl(String menuurl) {
			this.menuurl = menuurl;
		}
		public String getParentid() {
			return parentid;
		}
		public void setParentid(String parentid) {
			this.parentid = parentid;
		}
		/**
		 * 获取菜单子节点
		 *
		 * @Title: getMenu 
		 * @return: void
		 */
		public static List<SystemMenu> getMenus(String id){
			SqlSession ss=SessionFactory.getSqlSession();
			try {
				SystemMenuMapper mapper = ss.getMapper(SystemMenuMapper.class);
	            return mapper.selectChildren(id);
	        } finally {
	            ss.close();
	        }
		}
		/**
		 * 获取父节点
		 *
		 * @Title: getMenu 
		 * @param id
		 * @return
		 * @return: SystemMenu
		 */
		public static List<SystemMenu> getMenu(){
			SqlSession ss=SessionFactory.getSqlSession();
			try {
				SystemMenuMapper mapper = ss.getMapper(SystemMenuMapper.class);
				List<SystemMenu> menus=mapper.selectMenus();
	            return menus;
	        } finally {
	            ss.close();
	        }
		}
		
}
